<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :sm="24" :md="24" :xxl="16" v-if="!isBusiness">
            <a-form-item label="区域">
              <a-row :gutter="5" type="flex">
                <a-col :span="3">
                  <a-select
                    placeholder="省"
                    v-model="queryParam.provinceCode"
                    @change="e => addressChange(e, 'cityOptions', 'province')"
                  >
                    <a-select-option v-for="item in provinceOptions" :key="item.name" :value="item.code">
                      {{ item.name }}
                    </a-select-option>
                  </a-select>
                </a-col>
                <a-col :span="3">
                  <a-select
                    placeholder="市"
                    v-model="queryParam.cityCode"
                    @change="e => addressChange(e, 'areaOptions', 'city')"
                  >
                    <a-select-option v-for="item in cityOptions" :key="item.name" :value="item.code">
                      {{ item.name }}
                    </a-select-option>
                  </a-select>
                </a-col>
                <a-col :span="3">
                  <a-select
                    placeholder="区"
                    v-model="queryParam.areaCode"
                    @change="e => addressChange(e, 'streetOptions', 'area')"
                  >
                    <a-select-option v-for="item in areaOptions" :key="item.name" :value="item.code">
                      {{ item.name }}
                    </a-select-option>
                  </a-select>
                </a-col>
                <a-col :span="3">
                  <a-select
                    placeholder="街道"
                    v-model="queryParam.streetCode"
                    @change="e => addressChange(e, '', 'street')"
                  >
                    <a-select-option v-for="item in streetOptions" :key="item.name" :value="item.code">
                      {{ item.name }}
                    </a-select-option>
                  </a-select>
                </a-col>
                <a-col :span="4">
                  <a-select
                    placeholder="商家"
                    v-model="queryParam.businessId"
                    @change="e => agentChange(e, 'networkOptions', 'agentCode')"
                  >
                    <a-select-option v-for="item in agentOptions" :key="item.name" :value="item.code">
                      {{ item.name }}
                    </a-select-option>
                  </a-select>
                </a-col>
                <a-col :span="4">
                  <a-select
                    placeholder="网点"
                    v-model="queryParam.networkId"
                    @change="e => agentChange(e, 'deviceOptions', 'networkCode')"
                  >
                    <a-select-option v-for="item in networkOptions" :key="item.name" :value="item.code">
                      {{ item.name }}
                    </a-select-option>
                  </a-select>
                </a-col>
                <a-col :span="4">
                  <a-select placeholder="设备" v-model="queryParam.deviceId">
                    <a-select-option v-for="item in deviceOptions" :key="item.name" :value="item.code">
                      {{ item.name }}
                    </a-select-option>
                  </a-select>
                </a-col>
              </a-row>
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="12" :xl="8">
            <a-form-item label="流水项目">
              <!-- <a-select placeholder="请选择"> </a-select> -->
              <j-dict-select-tag allowClear v-model="queryParam.reviewType" placeholder="请选择" dictCode="flowName" />
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :sm="24" :md="12" :xl="8">
              <a-form-item label="流水ID">
                <a-input placeholder="请输入" v-model="queryParam.sequenceId"></a-input>
              </a-form-item>
            </a-col>
            <a-col :sm="24" :md="12" :xl="8">
              <a-form-item label="商家姓名">
                <a-input placeholder="请输入" v-model="queryParam.businessName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :sm="24" :md="12" :xl="8">
              <a-form-item label="订单ID">
                <a-input placeholder="请输入" v-model="queryParam.orderId"></a-input>
              </a-form-item>
            </a-col>
            <a-col :sm="24" :md="12" :xl="8">
              <a-form-item label="流水时间">
                <a-range-picker allowClear class="per100" v-model="tempTimes" @change="timeChange" />
              </a-form-item>
            </a-col>
            <a-col :sm="24" :md="12" :xl="8">
              <a-form-item label="复核状态">
                <j-dict-select-tag
                  allowClear
                  v-model="queryParam.capitalStatus"
                  placeholder="请选择"
                  dictCode="capitalStatus"
                />
              </a-form-item>
            </a-col>
          </template>

          <a-col :sm="24" :md="12" :xl="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button @click="searchReset()" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator mt10">
      <a-button type="primary" icon="download" @click="handleExportXls('资金流水')">导出</a-button>
    </div>

    <!-- table区域 -->
    <a-table
      ref="table"
      bordered
      size="middle"
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
      :scroll="{ x: 1200 }"
      @change="handleTableChange"
    >
      <span slot="action" slot-scope="text, record">
        <a-button type="primary" class="ml5 mr5" size="small">审批</a-button>
      </span>
    </a-table>
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { initDictOptions, filterDictText } from '@/components/dict/JDictSelectUtil'
import Api from '@/api/CashManage/CapitalFlow'
import { formatAmountFromFenToYuan } from '@/utils/util'
import { RoleMixin } from '@/mixins/roleUtil'
export default {
  name: 'CapitalFlow',
  mixins: [JeecgListMixin, RoleMixin],
  data() {
    return {
      url: {
        list: Api.list,
        exportXlsUrl: '/business/capitalFlow/exportXls'
      },
      columns: [],
      capitalStatusOptions: [],
      flowNameOptions: []
    }
  },
  created() {
    this.columns = [
      {
        title: '序号',
        dataIndex: 'index',
        align: 'center',
        customRender: (text, record, index) => `${index + 1}`
      },
      {
        title: '流水ID',
        align: 'center',
        dataIndex: 'sequenceId',
        sorter: (a, b) => {
          return a.sequenceId - b.sequenceId
        }
      },
      {
        title: '商家',
        align: 'center',
        dataIndex: 'businessName'
      },
      {
        title: '流水项目',
        dataIndex: 'flowName',
        align: 'center',
        customRender: (text, record, index) => {
          return filterDictText(this.flowNameOptions, text)
        },
        sorter: (a, b) => {
          return a.flowName - b.flowName
        }
      },
      {
        title: '流水金额',
        dataIndex: 'amount',
        align: 'center',
        sorter: (a, b) => {
          return a.amount - b.amount
        },
        customRender: (text, record, index) => {
          return formatAmountFromFenToYuan(text)
        }
      },
      {
        title: '订单ID',
        dataIndex: 'orderId',
        align: 'center',
        sorter: (a, b) => {
          return a.orderId - b.orderId
        }
      },
      {
        title: '流水时间',
        align: 'center',
        dataIndex: 'createTime',
        sorter: (a, b) => {
          return a.createTime - b.createTime
        }
      },
      {
        title: '复核状态',
        align: 'center',
        dataIndex: 'status',
        customRender: (text, record, index) => {
          //字典值替换通用方法
          return filterDictText(this.capitalStatusOptions, text)
        },
        sorter: (a, b) => {
          return a.status - b.status
        }
      }
    ]

    this.getAddress('provinceOptions')
  },
  methods: {
    // 初始化数据字典
    initDictConfig() {
      //初始化字典 - 是否
      initDictOptions('capitalStatus').then(res => {
        if (res.success) {
          this.capitalStatusOptions = res.result
        }
      })

      initDictOptions('flowName').then(res => {
        if (res.success) {
          this.flowNameOptions = res.result
        }
      })
    },

    // 创建时间改变
    timeChange(e, arr) {
      if (arr[0]) {
        this.queryParam.startTime = arr[0]
        this.queryParam.endTime = arr[1]
      } else {
        this.queryParam.startTime = undefined
        this.queryParam.endTime = undefined
      }
    }
  }
}
</script>

<style scoped></style>

